<?php
use think\facade\Db;
Db::name('mg_menu')
    ->whereOr("mg_module='{$mg_module}' and name = '答题管理'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/index'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/add'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/edit'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/del'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/del_option'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/down_temp'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/record'")
    ->whereOr("mg_module='{$mg_module}' and router = '{$mg_module}/Question/import'")
    ->delete();

$parent_id = Db::name('mg_menu')->insertGetId([
    'mg_module'     => $mg_module,
    'name'          => '答题管理',
    'module'        => $mg_module,
    'router'        => "",
    'controller'    => '',
    'action'        => '',
    'icon'          => 'layui-icon-read',
    'status'        => 1,
    'create_time'   => time()
]);
$insert_id = Db::name('mg_menu')->insertGetId([
    'parent_id'     => $parent_id,
    'mg_module'     => $mg_module,
    'name'          => '题库管理',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/index",
    'controller'    => 'Question',
    'action'        => 'index',
    'icon'          => '',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '添加题目',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/add",
    'controller'    => 'Question',
    'action'        => 'add',
    'icon'          => 'layui-icon-addition',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '编辑题目',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/edit",
    'controller'    => 'Question',
    'action'        => 'edit',
    'icon'          => 'layui-icon-edit',
    'style'         => 'layui-btn-xs layui-btn-normal',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '删除题目',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/del",
    'controller'    => 'Question',
    'action'        => 'del',
    'icon'          => 'layui-icon-delete',
    'style'         => 'layui-btn-xs layui-btn-danger',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '删除选项',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/del_option",
    'controller'    => 'Question',
    'action'        => 'del_option',
    'icon'          => 'layui-icon-delete',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '下载模板',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/down_temp",
    'controller'    => 'Question',
    'action'        => 'down_temp',
    'icon'          => 'layui-icon-download-circle',
    'style'         => 'layui-btn-xs layui-btn-danger',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $parent_id,
    'mg_module'     => $mg_module,
    'name'          => '答题记录',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/record",
    'controller'    => 'Question',
    'action'        => 'record',
    'status'        => 1,
    'create_time'   => time()
]);
Db::name('mg_menu')->insertGetId([
    'parent_id'     => $insert_id,
    'mg_module'     => $mg_module,
    'name'          => '题库导入',
    'module'        => $mg_module,
    'router'        => "{$mg_module}/Question/import",
    'controller'    => 'Question',
    'action'        => 'import',
    'status'        => 1,
    'create_time'   => time()
]);